package day14.Volatile;

import java.util.concurrent.atomic.AtomicInteger;

public class Lian03 {
    public static void main(String[] args) {
        ice2 a = new ice2();
        for (int i = 0; i < 100; i++) {
            new Thread(a).start();
        }
    }
}

class ice2 implements Runnable {
//    private volatile int count = 0;
//    private Object lock = new Object();
AtomicInteger ac=new AtomicInteger();
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
//            synchronized (lock) {
//                count++;
            int count = ac.incrementAndGet();
            System.out.println("已经送了" + count + "个冰淇淋");
            }
        }
    }

